package com.css.fxfzfxqh.modules.lifelineEngineering.utils;

import com.css.fxfzfxqh.constants.FxfzConstants;
import com.css.fxfzfxqh.modules.lifelineEngineering.repository.TaskManagementRepository;
import com.css.fxfzfxqh.util.PlatformObjectUtils;
import com.sun.istack.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@Configuration
public class VersionCodeUtils {

    @Autowired
    private TaskManagementRepository taskManagementRepository;

    public synchronized String getVersionCode(@NotNull String type,@NotNull String userId) {
        String versionCode = "";
        String code = taskManagementRepository.getCode(userId);
        if(PlatformObjectUtils.isNotEmpty(code)){
            String[] split = code.split("-");
            versionCode = split[3];
            StringBuilder stringBuilder = new StringBuilder();
            String t = String.valueOf(Integer.parseInt(versionCode) + 1);
            for (int i = t.length(); i < 4; i++) {
                stringBuilder.append("0");
            }
            versionCode = stringBuilder.append(t).toString();
        }else {
            versionCode = "0001";
        }
        versionCode = FxfzConstants.SMX_PG+"-"+"PG"+"-"+type+"-"+versionCode;
        return versionCode;
    }
}
